/**
 *  Premium URL Shortener jQuery Application
 *  Copyright @KBRmedia - All rights Reserved
 */

//鏁板瓧鏍煎紡鍖栦负鍗冧綅鏍囪瘑
function toThousands(num) {
    var num = (num || 0).toString(), re = /\d{3}$/, result = '';
    while ( re.test(num) ) {
        result = RegExp.lastMatch + result;
        if (num !== RegExp.lastMatch) {
            result = ',' + result;
            num = RegExp.leftContext;
        } else {
            num = '';
            break;
        }
    }
    if (num) { result = num + result; }
    return result;
}
function rules(){
	var area = [$(window).width() > 580 ? '580px' : '100%', '400px'];
	layer.open({
	  type: 2,
	  skin: 'layui-layer-rim', //鍔犱笂杈规
	  area: area, //瀹介珮
	  title: '链接内容管理规范',
	  content: './?mod=iiip'
	});
}
$(document).ready(function() {

	$.get("ajax.php?act=count",function(data){
		$("#count_dwz").text(toThousands(data.count_dwz));
		$("#count_tongji").text(toThousands(data.count_tongji));
		$("#count_vip").text(toThousands(data.count_vip));
	},'json');
	/**
	 * Shorten URL
	 **/
	// Ajax request: URL shortening and error handeling
	$("#shortenurl").click(function(e) {
		e.preventDefault();
		var url = $("#url").val();
		var type = $("#type").val();
		var dwz = $("#dwz").val();
		if(type == 1)var typename = '璺宠浆闃茬孩';
		else if(type == 2)var typename = '鐩存帴闃茬孩';
		else if(type == 3)var typename = '寰俊闃茬孩';
		if (url=='') {
			Snackbar.show({text: '请输入正确的网址！', backgroundColor: '#e22e40', textColor: '#fff', showAction: false });
			$('.main-input').addClass('error');
			return;
		}
		if($("#isagree").val()!='1') {
			Snackbar.show({text: '鎮ㄩ』鍚屾剰鎴戜滑鐨勬湇鍔℃潯娆炬墠鑳界敓鎴�', backgroundColor: '#e22e40', textColor: '#fff', showAction: false });
			return;
		}
		$.ajax({
			type: "POST",
			url: "./ajax.php?act=creat",
			data: {url: url, type: type, dwz: dwz},
			dataType: "json",
			beforeSend: function() {
				$('.shortbtnz').append("<div class='spinner-container-parent'><div class='spinner-container'><div class='spinner'><div class='spinner-left'><div class='spinner-circle'></div></div><div class='spinner-right'><div class='spinner-circle'></div></div></div></div></div>");
			},
			complete: function() {
				$('.shortbtnz').find('.spinner-container-parent').fadeOut("fast");
			},
			success: function(html) {
				if (html.code!=0) {
					Snackbar.show({text: html.msg, backgroundColor: '#e22e40', textColor: '#fff', showAction: false });
					$('.main-input').addClass('error');
				} else {
					$('.main-input').removeClass('error');
					/**$("#shortenurl").hide();
					$("#copyurl").show();   **/

					var url = html.dwz1;
					Snackbar.show({text: '鐢熸垚閾炬帴鎴愬姛', backgroundColor: '#1aa82c', textColor: '#fff', showAction: false });
					$('.modal-contentlink').html('<div class="panel-body"><div class="copy-link-block"><span class="short-url">' + url + '</span><button class="btn btn-primary" id="copyurlmodal" type="button" data-clipboard-text="' + url + '"><i class="zmdi zmdi-copy"></i></button></div><div class="qr"><img src="https://wenhairu.com/static/api/qr/?size=155&text=' + encodeURIComponent(url) + '" alt=""><a href="https://wenhairu.com/static/api/qr/?size=155&text=' + encodeURIComponent(url) + '" target="_blank" class="mdbtn btn btn-primary" data-value="https://wenhairu.com/static/api/qr/?size=155&text=' + encodeURIComponent(url) + '">淇濆瓨浜岀淮鐮�</a><br/><a href="tongji.php?id=' + html.id + '" target="_blank" class="mdbtn btn btn-success">鏌ョ湅缁熻</a><br/>褰撳墠濂楅锛�'+(html.isvip==1?'<a href="./pay.php" target="_blank" style="color:#ef7509">VIP鐗�</a>':'<a href="./pay.php" target="_blank" style="color:#0224a5">鍏嶈垂鐗�</a>')+'</div></div></div>');
					$('.overlaylink').fadeIn();
					$('.main-advanced').find('input').val('');
					//$('.main-input').val('');
					/**url.val(html.short);  
					url.select();
					var copy = new Clipboard('#copyurl');
					$("#submit").hide();
					$("#copyurl").attr("data-clipboard-text", url).show();
					copy.on('success', function(e) {
						Snackbar.show({text: '澶嶅埗鎴愬姛'});
						$("#copyurl").hide();
						$("#shortenurl").show();
						$('input.main-input').val('');
					});*/
					var copymodal = new Clipboard('#copyurlmodal');
					copymodal.on('success', function(e) {
						Snackbar.show({text: '澶嶅埗鎴愬姛'});
					});
				}

			}
		});
	});
	$("#agree").click(function() {
		var obj = $(this);
		obj.removeClass('btn-default');
		obj.addClass('btn-success');
		$("#isagree").val("1");
		$.cookie('agreerules', '1');
	});

	if($.cookie('agreerules') == '1')$("#agree").click();

	
});
/*window.cookieconsent.initialise({
    "palette": {
      "popup": {
        "background": "#2148b1"
      },
      "button": {
        "background": "#fff",
        "color": "#2148b1"
      }
    },
    "theme": "classic",
    "position": "bottom-right",
    "content": {
      "message": "杩戝嚑澶╅槻绾㈠湪鏇存柊锛屼笉绋冲畾锛屽湪鐮旂┒鏇存柊锛屾湰鍛ㄤ簲涔嬪墠鑳藉畬鎴愮ǔ瀹氥€�",
      "dismiss": "鍏堢敤鍏嶈垂鐨�",
      "link": "璐拱浠樿垂鐗�",
      "href": navigator.userAgent.indexOf("QQ/") > -1 ? "http://pay.420901.xyz" : "https://pay.91she.cn"
    }
  });
*/
